\hypertarget{internal__comm_8h}{
\section{internal\_\-comm.h File Reference}
\label{internal__comm_8h}\index{internal\_\-comm.h@{internal\_\-comm.h}}
}
The internal communication routines.  


\subsection*{Classes}
\begin{CompactItemize}
\item 
struct \hyperlink{structUC__MESSAGE}{UC\_\-MESSAGE}
\item 
struct \hyperlink{structstruct__uc__com}{struct\_\-uc\_\-com}
\end{CompactItemize}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define \hyperlink{internal__comm_8h_553542544a54f597b3d2d2704a76cb2b}{UC\_\-PREAMBLE\_\-FOUND}~0
\begin{CompactList}\small\item\em if the device is a motherboard we need to set the proper USARTs used \item\end{CompactList}\item 
\hypertarget{internal__comm_8h_6692f97fb35052c105fd1b57dc7005c6}{
\#define \hyperlink{internal__comm_8h_6692f97fb35052c105fd1b57dc7005c6}{UC\_\-MESSAGE\_\-IN\_\-BUFFER}~1}
\label{internal__comm_8h_6692f97fb35052c105fd1b57dc7005c6}

\begin{CompactList}\small\item\em Flag that a message is in the buffer. \item\end{CompactList}\item 
\hypertarget{internal__comm_8h_5707c99c71e5dd832214868c2e75634f}{
\#define \hyperlink{internal__comm_8h_5707c99c71e5dd832214868c2e75634f}{UC\_\-SIZE\_\-FIXED}~5}
\label{internal__comm_8h_5707c99c71e5dd832214868c2e75634f}

\begin{CompactList}\small\item\em Size of UC MESSAGE fixed part. \item\end{CompactList}\item 
\#define \hyperlink{internal__comm_8h_88cf69a74b6779dcf408122fccf68854}{UC\_\-COMM\_\-MSG\_\-PREAMBLE}~0xFE
\item 
\#define \hyperlink{internal__comm_8h_ebc23a7b60db897e42de4784ccbe4511}{UC\_\-COMM\_\-MSG\_\-POSTAMBLE}~0xFD
\item 
\#define \hyperlink{internal__comm_8h_dc1bd2e9a631be9894ccad2619eb72ca}{UC\_\-COMM\_\-MSG\_\-ACK}~0xFB
\item 
\#define \hyperlink{internal__comm_8h_2351b56552be2678354ae365881b62e0}{UC\_\-COMM\_\-MSG\_\-NACK}~0xFA
\item 
\hypertarget{internal__comm_8h_7c597134822ccbcee08bf0c8ca24929d}{
\#define \hyperlink{internal__comm_8h_7c597134822ccbcee08bf0c8ca24929d}{UC\_\-SERIAL\_\-RX\_\-BUFFER\_\-LENGTH}~20}
\label{internal__comm_8h_7c597134822ccbcee08bf0c8ca24929d}

\begin{CompactList}\small\item\em The length of the serial rx buffer used for communication between the uCs. \item\end{CompactList}\item 
\hypertarget{internal__comm_8h_579bfb56bf1877f1a43cc183e966f309}{
\#define \hyperlink{internal__comm_8h_579bfb56bf1877f1a43cc183e966f309}{UC\_\-MESSAGE\_\-DATA\_\-SIZE}~15}
\label{internal__comm_8h_579bfb56bf1877f1a43cc183e966f309}

\begin{CompactList}\small\item\em The size the data sent between the two devices can be maximum. \item\end{CompactList}\item 
\hypertarget{internal__comm_8h_32e7159be7cf3dbd975495b32dbe1135}{
\#define \hyperlink{internal__comm_8h_32e7159be7cf3dbd975495b32dbe1135}{UC\_\-COMM\_\-RX\_\-TIMEOUT}~3}
\label{internal__comm_8h_32e7159be7cf3dbd975495b32dbe1135}

\begin{CompactList}\small\item\em After this many ms it will reset the rx flags (in ms). \item\end{CompactList}\item 
\hypertarget{internal__comm_8h_87493b6d3503b0344548836ad9ee9878}{
\#define \hyperlink{internal__comm_8h_87493b6d3503b0344548836ad9ee9878}{UC\_\-COMM\_\-TX\_\-TIMEOUT}~10}
\label{internal__comm_8h_87493b6d3503b0344548836ad9ee9878}

\begin{CompactList}\small\item\em After this many ms a resend will occur if a message has not been acked (in ms). \item\end{CompactList}\item 
\hypertarget{internal__comm_8h_290343a67067544540f528c90bb05814}{
\#define \hyperlink{internal__comm_8h_290343a67067544540f528c90bb05814}{UC\_\-COMM\_\-RESEND\_\-COUNT}~5}
\label{internal__comm_8h_290343a67067544540f528c90bb05814}

\begin{CompactList}\small\item\em Number of resends that is allowed. \item\end{CompactList}\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
void \hyperlink{internal__comm_8h_038459fe5d58ddbde1ed8459d3b9bbce}{internal\_\-comm\_\-init} (void($\ast$func\_\-ptr\_\-rx)(\hyperlink{structUC__MESSAGE}{UC\_\-MESSAGE}), void($\ast$func\_\-ptr\_\-tx)(char))
\begin{CompactList}\small\item\em Initialize the internal communication. \item\end{CompactList}\item 
unsigned char \hyperlink{internal__comm_8h_64c4f318386e5cad700f6c5e08677c6f}{internal\_\-comm\_\-poll\_\-rx\_\-queue} (void)
\begin{CompactList}\small\item\em Polls the RX queue in the internal communication and calls the function defined in internal\_\-comm\_\-init. \item\end{CompactList}\item 
unsigned char \hyperlink{internal__comm_8h_35f8e503f80c8e1188ad09c1c0dde6ec}{internal\_\-comm\_\-poll\_\-tx\_\-queue} (void)
\begin{CompactList}\small\item\em Polls the TX queue in the internal communication and sends the data if there is a message in the queue. \item\end{CompactList}\item 
void \hyperlink{internal__comm_8h_d9191f782631f96ebe7a5d9d846ba97b}{internal\_\-comm\_\-add\_\-tx\_\-message} (unsigned char command, unsigned char length, char $\ast$data)
\begin{CompactList}\small\item\em Add a message to the transmit queue. \item\end{CompactList}\item 
\hypertarget{internal__comm_8h_fbadb98b60aabeefe61ca1d21ec183db}{
void \hyperlink{internal__comm_8h_fbadb98b60aabeefe61ca1d21ec183db}{internal\_\-comm\_\-send\_\-ack} (void)}
\label{internal__comm_8h_fbadb98b60aabeefe61ca1d21ec183db}

\begin{CompactList}\small\item\em Send an ACK message to the internal communication uart. \item\end{CompactList}\item 
\hypertarget{internal__comm_8h_17a9a942903f42bd140b2cd0e2486161}{
void \hyperlink{internal__comm_8h_17a9a942903f42bd140b2cd0e2486161}{internal\_\-comm\_\-send\_\-nack} (void)}
\label{internal__comm_8h_17a9a942903f42bd140b2cd0e2486161}

\begin{CompactList}\small\item\em Send a NACK message to the internal communication uart. \item\end{CompactList}\item 
void \hyperlink{internal__comm_8h_b19320006eb32811d9c211f41e229f87}{internal\_\-comm\_\-send\_\-message} (\hyperlink{structUC__MESSAGE}{UC\_\-MESSAGE} tx\_\-message)
\begin{CompactList}\small\item\em Send a message to the internal communication uart. \item\end{CompactList}\item 
\hypertarget{internal__comm_8h_7db36f8f06871f98ad2effe0484aaacb}{
void \hyperlink{internal__comm_8h_7db36f8f06871f98ad2effe0484aaacb}{internal\_\-comm\_\-reset\_\-rx} (void)}
\label{internal__comm_8h_7db36f8f06871f98ad2effe0484aaacb}

\begin{CompactList}\small\item\em Will reset the RX variables. \item\end{CompactList}\item 
\hypertarget{internal__comm_8h_bfbe070c4b84a6b49bbf3db2a1d2e98d}{
void \hyperlink{internal__comm_8h_bfbe070c4b84a6b49bbf3db2a1d2e98d}{internal\_\-comm\_\-1ms\_\-timer} (void)}
\label{internal__comm_8h_bfbe070c4b84a6b49bbf3db2a1d2e98d}

\begin{CompactList}\small\item\em Function which should be called each ms. \item\end{CompactList}\item 
\hypertarget{internal__comm_8h_37cb0731cb2b98770a5a67dfdd0303c6}{
void \hyperlink{internal__comm_8h_37cb0731cb2b98770a5a67dfdd0303c6}{internal\_\-comm\_\-resend} (void)}
\label{internal__comm_8h_37cb0731cb2b98770a5a67dfdd0303c6}

\begin{CompactList}\small\item\em Will trigger a resend of the last message. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
The internal communication routines. 

\begin{Desc}
\item[Author:]Mikael Larsmark, SM2WMV \end{Desc}
\begin{Desc}
\item[Date:]2010-01-25 

\begin{Code}\begin{verbatim} #include "internal_comm.h" 
\end{verbatim}
\end{Code}

 \end{Desc}


Definition in file \hyperlink{internal__comm_8h-source}{internal\_\-comm.h}.

\subsection{Define Documentation}
\hypertarget{internal__comm_8h_dc1bd2e9a631be9894ccad2619eb72ca}{
\index{internal\_\-comm.h@{internal\_\-comm.h}!UC\_\-COMM\_\-MSG\_\-ACK@{UC\_\-COMM\_\-MSG\_\-ACK}}
\index{UC\_\-COMM\_\-MSG\_\-ACK@{UC\_\-COMM\_\-MSG\_\-ACK}!internal_comm.h@{internal\_\-comm.h}}
\subsubsection[{UC\_\-COMM\_\-MSG\_\-ACK}]{\setlength{\rightskip}{0pt plus 5cm}\#define UC\_\-COMM\_\-MSG\_\-ACK~0xFB}}
\label{internal__comm_8h_dc1bd2e9a631be9894ccad2619eb72ca}


The acknowledge command of the bus 

Definition at line 73 of file internal\_\-comm.h.

Referenced by internal\_\-comm\_\-send\_\-ack(), and ISR().\hypertarget{internal__comm_8h_2351b56552be2678354ae365881b62e0}{
\index{internal\_\-comm.h@{internal\_\-comm.h}!UC\_\-COMM\_\-MSG\_\-NACK@{UC\_\-COMM\_\-MSG\_\-NACK}}
\index{UC\_\-COMM\_\-MSG\_\-NACK@{UC\_\-COMM\_\-MSG\_\-NACK}!internal_comm.h@{internal\_\-comm.h}}
\subsubsection[{UC\_\-COMM\_\-MSG\_\-NACK}]{\setlength{\rightskip}{0pt plus 5cm}\#define UC\_\-COMM\_\-MSG\_\-NACK~0xFA}}
\label{internal__comm_8h_2351b56552be2678354ae365881b62e0}


The NOT acknowledge command of the bus 

Definition at line 75 of file internal\_\-comm.h.

Referenced by internal\_\-comm\_\-send\_\-nack(), and ISR().\hypertarget{internal__comm_8h_ebc23a7b60db897e42de4784ccbe4511}{
\index{internal\_\-comm.h@{internal\_\-comm.h}!UC\_\-COMM\_\-MSG\_\-POSTAMBLE@{UC\_\-COMM\_\-MSG\_\-POSTAMBLE}}
\index{UC\_\-COMM\_\-MSG\_\-POSTAMBLE@{UC\_\-COMM\_\-MSG\_\-POSTAMBLE}!internal_comm.h@{internal\_\-comm.h}}
\subsubsection[{UC\_\-COMM\_\-MSG\_\-POSTAMBLE}]{\setlength{\rightskip}{0pt plus 5cm}\#define UC\_\-COMM\_\-MSG\_\-POSTAMBLE~0xFD}}
\label{internal__comm_8h_ebc23a7b60db897e42de4784ccbe4511}


The postamble of the BUS message 

Definition at line 71 of file internal\_\-comm.h.

Referenced by internal\_\-comm\_\-send\_\-ack(), internal\_\-comm\_\-send\_\-message(), internal\_\-comm\_\-send\_\-nack(), and ISR().\hypertarget{internal__comm_8h_88cf69a74b6779dcf408122fccf68854}{
\index{internal\_\-comm.h@{internal\_\-comm.h}!UC\_\-COMM\_\-MSG\_\-PREAMBLE@{UC\_\-COMM\_\-MSG\_\-PREAMBLE}}
\index{UC\_\-COMM\_\-MSG\_\-PREAMBLE@{UC\_\-COMM\_\-MSG\_\-PREAMBLE}!internal_comm.h@{internal\_\-comm.h}}
\subsubsection[{UC\_\-COMM\_\-MSG\_\-PREAMBLE}]{\setlength{\rightskip}{0pt plus 5cm}\#define UC\_\-COMM\_\-MSG\_\-PREAMBLE~0xFE}}
\label{internal__comm_8h_88cf69a74b6779dcf408122fccf68854}


The preamble of the BUS message 

Definition at line 69 of file internal\_\-comm.h.

Referenced by internal\_\-comm\_\-send\_\-ack(), internal\_\-comm\_\-send\_\-message(), internal\_\-comm\_\-send\_\-nack(), and ISR().\hypertarget{internal__comm_8h_553542544a54f597b3d2d2704a76cb2b}{
\index{internal\_\-comm.h@{internal\_\-comm.h}!UC\_\-PREAMBLE\_\-FOUND@{UC\_\-PREAMBLE\_\-FOUND}}
\index{UC\_\-PREAMBLE\_\-FOUND@{UC\_\-PREAMBLE\_\-FOUND}!internal_comm.h@{internal\_\-comm.h}}
\subsubsection[{UC\_\-PREAMBLE\_\-FOUND}]{\setlength{\rightskip}{0pt plus 5cm}\#define UC\_\-PREAMBLE\_\-FOUND~0}}
\label{internal__comm_8h_553542544a54f597b3d2d2704a76cb2b}


if the device is a motherboard we need to set the proper USARTs used 

if the device is a frontpanel we need to set the proper USARTs used Preamble found for the communication between the uCs 

Definition at line 61 of file internal\_\-comm.h.

Referenced by ISR().

\subsection{Function Documentation}
\hypertarget{internal__comm_8h_d9191f782631f96ebe7a5d9d846ba97b}{
\index{internal\_\-comm.h@{internal\_\-comm.h}!internal\_\-comm\_\-add\_\-tx\_\-message@{internal\_\-comm\_\-add\_\-tx\_\-message}}
\index{internal\_\-comm\_\-add\_\-tx\_\-message@{internal\_\-comm\_\-add\_\-tx\_\-message}!internal_comm.h@{internal\_\-comm.h}}
\subsubsection[{internal\_\-comm\_\-add\_\-tx\_\-message}]{\setlength{\rightskip}{0pt plus 5cm}void internal\_\-comm\_\-add\_\-tx\_\-message (unsigned char {\em command}, \/  unsigned char {\em length}, \/  char $\ast$ {\em data})}}
\label{internal__comm_8h_d9191f782631f96ebe7a5d9d846ba97b}


Add a message to the transmit queue. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em command}]The command we wish to perform \item[{\em length}]The length of the data field \item[{\em data}]The data we wish to send \end{description}
\end{Desc}


Definition at line 166 of file internal\_\-comm.c.

References UC\_\-MESSAGE::checksum, UC\_\-MESSAGE::cmd, UC\_\-MESSAGE::data, int\_\-comm\_\-tx\_\-queue\_\-add(), and UC\_\-MESSAGE::length.

Referenced by antenna\_\-ctrl\_\-deactivate\_\-outputs(), antenna\_\-ctrl\_\-send\_\-ant\_\-data\_\-to\_\-bus(), antenna\_\-ctrl\_\-send\_\-rx\_\-ant\_\-band\_\-data\_\-to\_\-bus(), antenna\_\-ctrl\_\-send\_\-rx\_\-ant\_\-data\_\-to\_\-bus(), band\_\-ctrl\_\-send\_\-band\_\-data\_\-to\_\-bus(), computer\_\-interface\_\-parse\_\-data(), main(), parse\_\-internal\_\-comm\_\-message(), ps2\_\-process\_\-key(), radio\_\-poll\_\-status(), shutdown\_\-device(), and sub\_\-menu\_\-send\_\-data\_\-to\_\-bus().\hypertarget{internal__comm_8h_038459fe5d58ddbde1ed8459d3b9bbce}{
\index{internal\_\-comm.h@{internal\_\-comm.h}!internal\_\-comm\_\-init@{internal\_\-comm\_\-init}}
\index{internal\_\-comm\_\-init@{internal\_\-comm\_\-init}!internal_comm.h@{internal\_\-comm.h}}
\subsubsection[{internal\_\-comm\_\-init}]{\setlength{\rightskip}{0pt plus 5cm}void internal\_\-comm\_\-init (void($\ast$)({\bf UC\_\-MESSAGE}) {\em func\_\-ptr\_\-rx}, \/  void($\ast$)(char) {\em func\_\-ptr\_\-tx})}}
\label{internal__comm_8h_038459fe5d58ddbde1ed8459d3b9bbce}


Initialize the internal communication. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em func\_\-ptr\_\-rx}]The function you wish to call when a new message has been recieved and should be parsed \item[{\em func\_\-ptr\_\-tx}]The function used to send data to the hardware handeling the data transmission \end{description}
\end{Desc}


Definition at line 68 of file internal\_\-comm.c.

References struct\_\-uc\_\-com::char\_\-count, struct\_\-uc\_\-com::checksum, f\_\-ptr\_\-rx, f\_\-ptr\_\-tx, struct\_\-uc\_\-com::flags, int\_\-comm\_\-rx\_\-queue\_\-dropall(), and int\_\-comm\_\-tx\_\-queue\_\-dropall().

Referenced by main().\hypertarget{internal__comm_8h_64c4f318386e5cad700f6c5e08677c6f}{
\index{internal\_\-comm.h@{internal\_\-comm.h}!internal\_\-comm\_\-poll\_\-rx\_\-queue@{internal\_\-comm\_\-poll\_\-rx\_\-queue}}
\index{internal\_\-comm\_\-poll\_\-rx\_\-queue@{internal\_\-comm\_\-poll\_\-rx\_\-queue}!internal_comm.h@{internal\_\-comm.h}}
\subsubsection[{internal\_\-comm\_\-poll\_\-rx\_\-queue}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char internal\_\-comm\_\-poll\_\-rx\_\-queue (void)}}
\label{internal__comm_8h_64c4f318386e5cad700f6c5e08677c6f}


Polls the RX queue in the internal communication and calls the function defined in internal\_\-comm\_\-init. 

\begin{Desc}
\item[Returns:]1 if a message was in the buffer and got parsed, 0 if not \end{Desc}


Definition at line 91 of file internal\_\-comm.c.

References f\_\-ptr\_\-rx, int\_\-comm\_\-rx\_\-queue\_\-drop(), int\_\-comm\_\-rx\_\-queue\_\-get(), and int\_\-comm\_\-rx\_\-queue\_\-is\_\-empty().

Referenced by main().\hypertarget{internal__comm_8h_35f8e503f80c8e1188ad09c1c0dde6ec}{
\index{internal\_\-comm.h@{internal\_\-comm.h}!internal\_\-comm\_\-poll\_\-tx\_\-queue@{internal\_\-comm\_\-poll\_\-tx\_\-queue}}
\index{internal\_\-comm\_\-poll\_\-tx\_\-queue@{internal\_\-comm\_\-poll\_\-tx\_\-queue}!internal_comm.h@{internal\_\-comm.h}}
\subsubsection[{internal\_\-comm\_\-poll\_\-tx\_\-queue}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char internal\_\-comm\_\-poll\_\-tx\_\-queue (void)}}
\label{internal__comm_8h_35f8e503f80c8e1188ad09c1c0dde6ec}


Polls the TX queue in the internal communication and sends the data if there is a message in the queue. 

\begin{Desc}
\item[Returns:]1 if a message was in the buffer and got sent, 0 if not \end{Desc}


Definition at line 105 of file internal\_\-comm.c.

References int\_\-comm\_\-tx\_\-queue\_\-get(), int\_\-comm\_\-tx\_\-queue\_\-is\_\-empty(), internal\_\-comm\_\-send\_\-message(), and msg\_\-not\_\-acked.

Referenced by main().\hypertarget{internal__comm_8h_b19320006eb32811d9c211f41e229f87}{
\index{internal\_\-comm.h@{internal\_\-comm.h}!internal\_\-comm\_\-send\_\-message@{internal\_\-comm\_\-send\_\-message}}
\index{internal\_\-comm\_\-send\_\-message@{internal\_\-comm\_\-send\_\-message}!internal_comm.h@{internal\_\-comm.h}}
\subsubsection[{internal\_\-comm\_\-send\_\-message}]{\setlength{\rightskip}{0pt plus 5cm}void internal\_\-comm\_\-send\_\-message ({\bf UC\_\-MESSAGE} {\em tx\_\-message})}}
\label{internal__comm_8h_b19320006eb32811d9c211f41e229f87}


Send a message to the internal communication uart. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em tx\_\-message}]The message we wish to send \end{description}
\end{Desc}


Definition at line 147 of file internal\_\-comm.c.

References UC\_\-MESSAGE::checksum, UC\_\-MESSAGE::cmd, counter\_\-tx\_\-timeout, UC\_\-MESSAGE::data, f\_\-ptr\_\-tx, UC\_\-MESSAGE::length, UC\_\-COMM\_\-MSG\_\-POSTAMBLE, and UC\_\-COMM\_\-MSG\_\-PREAMBLE.

Referenced by internal\_\-comm\_\-poll\_\-tx\_\-queue(), and internal\_\-comm\_\-resend().